<template>
  <el-form ref="userForm" :rules="rules" :model="userInfo" label-width="120px" style="margin-left: 120px; margin-top: 30px">
    <el-form-item label="姓名:" prop="username">
      <el-input v-model="userInfo.username" style="width: 300px" />
    </el-form-item>
    <el-form-item label="密码:">
      <el-input v-model="userInfo.password" type="password" style="width: 300px" />
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="hEdit">更新</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
import { getUserDetailInfo } from '@/api/user'
import { updateEmployeeInfo } from '@/api/employees'
export default {
  data() {
    return {
      userInfo: {
        username: '',
        password: ''
      },
      rules: {
        username: [{ required: true, message: '用户名不能为空', triggler: 'blur' }]
      }
    }
  },
  created() {
    this.loadUerDetailInfo()
  },
  methods: {
    // 根据id获取用户的基本信息
    async loadUerDetailInfo() {
      const res = await getUserDetailInfo(this.$route.params.id)
      this.userInfo = res.data
    },
    // 点击更新修改,这个功能做不了，接口好像有问题
    async hEdit() {
      // 兜底校验
      await this.$refs.userForm.validate()
      try {
        //  发请求
        const res = await updateEmployeeInfo(this.$route.params.id)
        // console.log(res)
        // 提示用户
        this.$message.success(res.message)
      } catch (error) {
        // this.$message.error(error.message)
      }
    }
  }
}
</script>
